import Vue from 'vue'
import VueRouter from 'vue-router'
import api from "../http/api"

import Home from '../views/Home.vue'
import Login from '../views/login.vue'
// import Register from '../views/register.vue'
import addstudents from '../components/addstudents.vue'
import liststudents from '../components/liststudents.vue'
import xgstudent from '../components/xgstudent.vue'
import listclass from '../components/listclass.vue'
import addclass from '../components/addclass.vue'
import listsubjects from '../components/listsubjects.vue'
import addsubjects from '../components/addsubjects.vue'
// import ssumum from '../components/ssumum.vue'
import users from '../http/modules/users'




const Register = () => import('../views/register.vue')
const count = () => import('../components/count.vue')

 
Vue.use(VueRouter)
//配置路由
const routes = [
  {
    path: '/Home',
    name: 'Home',
    component: Home,
    // beforeEnter: async (to, from, next) => {
    //   if (localStorage.token) {
    //     const data = await api.users.getUserInfo()

    //     if (data.code) {
    //      next()
    //     }
    //   } else {
    //     alert('你还未登录，请登陆');
    //     next('/login')
    //   }
    // },
    children: [
      {
         path: 'addstudents',
           name: 'Addstudents',
           component: addstudents,
      },
       {
         path: 'liststudents',
         name: 'Liststudents',
         component: liststudents,
       },
      {
         //动态路由
        path: 'xgstudent/:_id',
        props: true,
         name: 'xgstudent',
         component: xgstudent,
       },
      {
         //班级
        path: 'listclass',
        // props: true,
         name: 'listclass',
         component: listclass,
       },
      {
         //班级
        path: 'addclass',
        // props: true,
         name: 'addclass',
         component: addclass,
       },
      {
         //班级
        path: 'listsubjects',
        // props: true,
         name: 'listsubjects',
         component: listsubjects,
       },
      {
         //班级
        path: 'addsubjects',
        // props: true,
         name: 'addsubjects',
         component: addsubjects,
      },
      {
        path: 'count',
        name: 'count',
        component: count,


      },

    ]
  },
  {
    path: '/login',
    name: 'Login',
    component: Login
  },
  {
    path: '/register',
    name: 'Register',
    component: Register,

    
  },
  
]

const router = new VueRouter({
  routes: routes,
    mode: 'history'
})
//全局前置守卫
// router.beforeEach((to, from, next) => {
//   if (to.path.includes('Home')) {
//     //判断用户是否登陆
//     if (localStorage.token) {
//       next()
//     } else {
//       alert('你还未登录，请先登陆');
//     next('/login')
//   }
//   } else {
//     next()
//   }

// })


export default router
